package com.example.goods_manage.service.impl;

import com.example.goods_manage.mapper.CategoryMapper;
import com.example.goods_manage.service.CategoryService;
import com.example.goods_manage.utils.AjaxResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <P> @Author: SongKeCheng
 * <P> Type: Class
 * <P> Description:
 * <P> Date: 2024/7/19:14:21
 */

@SuppressWarnings({"unchecked", ""})
@Service
public class CategoryServiceImpl implements CategoryService {
    private static final Logger log = LoggerFactory.getLogger(CategoryServiceImpl.class);

    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public List findAllCategory() {
        return categoryMapper.findAllCategory();
    }


    @Override
    public AjaxResult statisticsCategory() {
        Map<String, Object> resultMap = new HashMap<>();
        List<Map> result = categoryMapper.statisticsCategory();

        //List<String> list = new ArrayList<>();
        //for (Map map : result) {
        //    list.add((String) map.get("name"));
        //}

        List<String> name = result.stream().map(map -> map.get("name").toString()).collect(Collectors.toList());


        //名称
        resultMap.put("legendData",name);
        //名称和数量
        resultMap.put("seriesData",result);
        return AjaxResult.success(resultMap);
    }
}
